package gov.nbcs.govp.jhgl.ui.thread;



import com.foundercy.pf.control.FPageRoller;
import com.foundercy.pf.control.Rollable;
import com.foundercy.pf.control.table.FTable;
import com.foundercy.pf.gl.dao.ConditionObj;
import com.foundercy.pf.util.FPaginationDTO;


import gov.nbcs.govp.common.bean.PageListBean;
import gov.nbcs.govp.common.ui.DisplayPanel;
import gov.nbcs.govp.common.util.PlatformTools;
import gov.nbcs.govp.jhgl.ibs.IGovpPlanBusiness;

import java.awt.Component;
import java.awt.Cursor;
import java.util.List;

public class GovpPlanForAdjustDown extends Thread implements Rollable {

	private IGovpPlanBusiness planBusiness;

	private DisplayPanel panel;

	private FPageRoller pageRoller;

	private String Sql;

	// String find_sql="";

	public GovpPlanForAdjustDown(DisplayPanel panel,
			IGovpPlanBusiness planBusiness, FPageRoller pageRoller, String Sql) {
		super();
		this.panel = panel;
		this.planBusiness = planBusiness;
		this.Sql = Sql;
		this.pageRoller=pageRoller;

	}

	public void run() {

		if (pageRoller.getTotalRows() == 0) {
			pageRoller.setPageRows(new FPaginationDTO().getPagecount());
			pageRoller.setRollable(this);
		} else {
			pageRoller.addRollable(this);
			pageRoller.onJump(pageRoller.getCurrentPageIndex());
		}

	}

	public int jump(int pageIndex, int pageRows) {
		// TODO Auto-generated method stub

		try {
		

			panel.setCursor(new Cursor(Cursor.WAIT_CURSOR));
			FPaginationDTO page = new FPaginationDTO();
			page.setCurrpage(pageIndex);
			page.setPagecount(pageRows);

			ConditionObj obj = new ConditionObj();
			FTable table = panel.getOperationTable()[1];

			Component c = PlatformTools.replaceTableAsDoing(table);
			PageListBean pagelist = planBusiness.getGovpPlanDataforAdjust(panel
					.getUser(), page, Sql);

			List list = pagelist.getDataList();
			PlatformTools.replaceTableAsDone(c, table);
			table.setData(list);
			panel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
			return pagelist.getTotalrows();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return 0;
		}
	}

}
